#include "skillmodel.h"
#include "skill.h"


#include <QMetaObject>
#include <QMetaProperty>
#include <QDebug>


SkillModel::SkillModel(QObject *parent) :
    QSortFilterProxyModel(parent)
{
    connect(this, &SkillModel::layoutChanged, this, &SkillModel::rowCountChanged);
    connect(this, &SkillModel::rowsInserted, this, &SkillModel::rowCountChanged);
    connect(this, &SkillModel::rowsRemoved, this, &SkillModel::rowCountChanged);
}

QHash<int, QByteArray> SkillModel::roleNames() const
{
    QHash<int, QByteArray> ret;
    ret.insert(Qt::DisplayRole, "skill");
    return ret;
}

QVariant SkillModel::data(const QModelIndex &index, int role) const
{
    if (role != Qt::DisplayRole || !index.isValid())
    {
        return QVariant();
    }

    QModelIndex source = mapToSource(index);
    if (!source.isValid())
    {
        return QVariant();
    }

    return QVariant::fromValue<ModelItem*>(reinterpret_cast<ModelItem*>(source.internalPointer()));
}

QObject *SkillModel::get(int row) const
{
    QModelIndex proxy = index(row, 0);
    if (!proxy.isValid())
    {
        return 0;
    }

    QModelIndex source = mapToSource(proxy);
    if (!source.isValid())
    {
        return 0;
    }

    return reinterpret_cast<QObject*>(source.internalPointer());
}





